﻿<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="FastSpring.Core.Model.Function,FastSpring.Net.Core" table="Sys_Function" lazy="false">
    <id name="FID" column="FID" type="Int32">
      <generator class="native" />
    </id>
    <property name="FunCode" column="FunCode"/>
    <property name="FunName" column="FunName"/>
    <property name="OrdNum" column="OrdNum"/>
    <property name="IsActive" column="IsActive"/>
    <many-to-one name="ParentFunction" 
      class="FastSpring.Core.Model.Function,FastSpring.Net.Core" 
      cascade="none" 
      column="PFID" 
      not-null="false"/>
    <bag name="SubFunctions" cascade="none" inverse="true" lazy="false" order-by="OrdNum">
      <key column="PFID"/>
      <one-to-many class="FastSpring.Core.Model.Function,FastSpring.Net.Core" />
    </bag>
    <bag name="FunctionModules" cascade="none" inverse="false" lazy="false" order-by="FMID">
      <key column="FID"/>
      <one-to-many class="FastSpring.Core.Model.FunctionModule,FastSpring.Net.Core" />
    </bag>
  </class>
  <class name="FastSpring.Core.Model.FunctionModule,FastSpring.Net.Core" table="Sys_FunctionModule" lazy="false">
    <id name="FMID" column="FMID" type="Int32">
      <generator class="native" />
    </id>
    <property name="ModuleButton" column="ModuleButton"/>
    <property name="Description" column="Description"/>
    <property name="IsSubModuleAll" column="IsSubModuleAll"/>    
    <many-to-one name="Function" 
      class="FastSpring.Core.Model.Function,FastSpring.Net.Core" 
      cascade="none" 
      column="FID" 
      not-null="true"/>
    <many-to-one name="Module" 
      class="FastSpring.Core.Model.Module,FastSpring.Net.Core" 
      cascade="none" 
      column="MID" 
      not-null="true"/>
    <!--<bag name="SubFunctionModules" cascade="none" inverse="false" lazy="false" order-by="FMID">
      <key column="PFMID"/>
      <one-to-many class="FastSpring.Core.Model.FunctionModule,FastSpring.Net.Core" />
    </bag>-->
  </class>
  <class name="FastSpring.Core.Model.Module,FastSpring.Net.Core" table="Sys_Module" lazy="false">
    <id name="MID" column="MID" type="Int32">
      <generator class="native" />
    </id>
    <property name="Mcode" column="Mcode" />
    <property name="Mname" column="Mname" />
    <property name="Url" column="Url" />
    <property name="UrlName" column="UrlName" />
    <property name="Description" column="Description"/>
    <property name="IsActive" column="IsActive" />
    <many-to-one name="ParentModule" 
      class="FastSpring.Core.Model.Module,FastSpring.Net.Core" 
      cascade="none" 
      column="PMID" 
      not-null="false"/>
    <bag name="SubModules" cascade="none" inverse="false" lazy="false" order-by="Mcode">
      <key column="PMID"/>
      <one-to-many class="FastSpring.Core.Model.Module,FastSpring.Net.Core" />
    </bag>
    <bag name="ModuleButtons" cascade="none" inverse="false" lazy="false" order-by="ButtonCode">
      <key column="MID"/>
      <one-to-many class="FastSpring.Core.Model.ModuleButton,FastSpring.Net.Core" />
    </bag>
  </class>
  <class name="FastSpring.Core.Model.ModuleButton,FastSpring.Net.Core" table="Sys_ModuleButton" lazy="false">
    <id name="MBID" column="MBID" type="Int32">
      <generator class="native" />
    </id>
    <!--<property name="MID" column="MID"/>-->
    <property name="ButtonCode" column="ButtonCode"/>
    <property name="ButtonName" column="ButtonName"/>
    <property name="Description" column="Description"/>
    <property name="IsActive" column="IsActive"/>
    <many-to-one name="Module" 
      class="FastSpring.Core.Model.Module,FastSpring.Net.Core" 
      cascade="none" 
      column="MID" 
      not-null="true"/>
  </class>
  <query name="GetAllParentFunctionsList">
    <![CDATA[from Function function WHERE function.ParentFunction is null ORDER BY function.OrdNum]]>
  </query>
  <query name="GetAllParentModulesList">
    <![CDATA[from Module module WHERE module.ParentModule is null ORDER BY module.Mcode]]>
  </query>

  <query name="GetModuleCopy">
    <![CDATA[from Module module WHERE module.Mcode=:param1 ORDER BY module.MID DESC]]>
  </query>
  <!-- 下拉列表　 -->
  <query name="GetParentModulesList">
    <![CDATA[Select module.Mname,module.MID from Module module WHERE module.ParentModule is null ORDER BY module.Mcode]]>
  </query>
  <query name="GetParentFunctionsList">
    <![CDATA[Select function.FunName,function.FID from Function function WHERE function.ParentFunction is null ORDER BY function.OrdNum]]>
  </query>

  <!-- 删除模块时查询依赖 -->
  <query name="GetSubModulesOfMID">
    <![CDATA[from Module module WHERE module.ParentModule is not null AND module.ParentModule.MID=:ParentID]]>
  </query>
  <query name="GetModuleButtonsOfMID">
    <![CDATA[from ModuleButton moduleButton WHERE moduleButton.Module.MID=:ParentID]]>
  </query>
  <query name="GetFunctionModulesOfMID">
    <![CDATA[from FunctionModule functionModule WHERE functionModule.Module.MID=:ParentID]]>
  </query>  
  <!-- 删除功能模块时查询依赖 -->
  <query name="GetSubFunctionModulesOfFMID">
    <![CDATA[from FunctionModule functionModule WHERE functionModule.ParentFunctionModule.FMID=:ParentID]]>
  </query>

  <!-- 删除功能时查询依赖 -->
  <query name="GetFunctionModulesOfFID">
    <![CDATA[from FunctionModule functionModule WHERE functionModule.Function.FID=:ParentID]]>
  </query>
  <query name="GetSubFunctionsOfFID">
    <![CDATA[from Function function WHERE function.ParentFunction.FID=:ParentID]]>
  </query>
  <query name="GetRoleFunctionsOfFID">
    <![CDATA[from RoleFunction roleFunction WHERE roleFunction.Function.FID=:ParentID]]>
  </query>
</hibernate-mapping>
